﻿@{
    ViewBag.Title = "WorkItemIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var keyValue = "", _TypeId = "", organizeid = " @LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";

    $(function () {
        initControl();
        GetTree();
        GetGrid();
    })
    function initControl() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);
            }, 200);
            e.stopPropagation();
        });
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==选择所属机构==",
            height: "250px",
            click: function (data) {
                organizeid = data.id;
                $('#btn_Search').trigger("click");
            }
        });
        $("#OrganizeId").ComboBoxTreeSetValue(organizeid);
    }
    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeTreeJson",
            onnodeclick: function (item) {
                _TypeId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetGrid() {
        $gridTable = $("#gridTable");
        var queryJson = {
            keyValue: keyValue,
            Type: _TypeId,
            OrganizeId: organizeid,
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val()
        };
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_DeviceMaintance/GetWorkItemList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 115,
            autowidth: true,
            colModel: [
               { label: "主键", name: "Id", hidden: true },
               { label: "项目编号", name: "Code", index: "Code", width: 200, align: "center", sortable: false },
               { label: "项目名称", name: "Name", index: "Name", width: 200, align: "center", sortable: false },
               { label: "工作类型", name: "Type", index: "Type", width: 200, align: "center", sortable: false },
               { label: "工作内容", name: "Memo", index: "Memo", width: 400, align: "center", sortable: false },
               { label: "应用设备类型", name: "InstallType", index: "InstallType", width: 200, align: "center", sortable: false },
               { label: "应用设备等级", name: "Level", index: "Level", width: 200, align: "center", sortable: false },
               { label: "应用项目类型", name: "BllTypeId", index: "BllTypeId", width: 200, align: "center", sortable: false }
            ],
            viewrecords: true,
            treeGrid: true,
            rowNum: "all",
            rownumbers: true,

        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                keyValue: keyValue,
                Type: _TypeId,
                OrganizeId: organizeid,
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val(),
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        })

    }

    function btn_add() {
        dialogOpen({
            id: "WorkItemForm",
            title: '添加工作项目',
            url: '/PropertyManage/CS_DeviceMaintance/Form',
            width: "1000px",
            height: "800px",
            callBack: function (iframeId) {
                top.frames["WorkItemForm"].AcceptClick();
            }
        })
    }

    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "WorkItemForm",
                title: '修改信息',
                url: '/PropertyManage/CS_DeviceMaintance/Form?keyValue=' + keyValue,
                width: "1000px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames["WorkItemForm"].AcceptClick();

                }
            });
        }
    }

    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_DeviceMaintance/RemoveWorkItemForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $('#btn_Search').trigger("click");
                }
            })
        }
    }
    function btn_worktype() {
        top.tablist.newTab({
            id: "WorkTypeIndex",
            title: "项目类型",
            closed: true,
            replace: true,
            icon: "fa fa-file-text-o",
            url: top.contentPath + "/PropertyManage/CS_DeviceMaintance/TypeIndex"
        });
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">项目类型</div>
            <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr> 
                            <td>
                                <div id="OrganizeId" style="width:150px;" type="selectTree" class="ui-select"></div>
                            </td>
                            <td style="padding-left: 2px;">
                                <div class="btn-group" id="queryCondition">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>

                        </tr>

                    </table>
                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                        <div class="btn-group">
                            <a id="lr-more" class="btn btn-default" data-toggle="dropdown"><i class="fa fa-reorder"></i>&nbsp;更多操作<span class="caret"></span></a>
                            <ul class="dropdown-menu pull-right">
                                <li id="lr-type"><a onclick="btn_worktype()"><i></i>&nbsp;项目类型</a></li> 
                            </ul> 
                        </div>
                      </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>

            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>